export default function callCloud(app, lib) {
  return function callCloud(url, param={}, ctx) {
    if (lib.isString(url)) {
      let ary = url.split('/')
      if (!ary[0]) {
        ary.shift()
      }
      if (ary.length) {
        let api = ary[0]
        let coll = ary[1]
        let action = ary[2]
        let dataKey = ary[3]

        param.__collection__ = coll
        param.__action__ = action
        param.__datakey__ = dataKey
        // param.__createtime__ = dataKey
        if (typeof wx === 'undefined') {
          param.__web_uid__ = 'administrator'
        }
        return new Promise((resolve, rej)=>{
          app.callFunction({
            name: api,
            data: param,
          })
          .then((res) => {
            resolve(res)
          })
          .catch(console.error);
        })
      }
    }
  }
}